package com.sojson.config.converter.fastjson;

import java.io.IOException;
import java.lang.reflect.Type;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * 空值不序列化
 * 
 * @author liu
 * @date 2021-09-28
 */
public class NullNoOutFeature implements ObjectSerializer {

    /**
     * 序列化属性
     * 
     * @param serializer
     * @param object        字段值
     * @param fieldName     字段名
     * @param fieldType     字段类型
     * @param features
     * @throws IOException
     */
    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
        throws IOException {
        // 空值不序列化
        serializer.config(SerializerFeature.WriteMapNullValue, false);
        // 序列化属性
        serializer.write(object);
    }

}